<style>
    /* 根据字数修改 */
    .layui-form-label {
        width: 60px;
    }
</style>
<div class="layuimini-container layuimini-page-anim">
    <!-- 用于创建子页面 -->
    <div class="page-create"></div>

    <!-- page-main-create -->
    <!-- 用于显示 隐藏 -->
    <div class="layuimini-main page-main-create">
        <div class="title-row pb-0 layuimini-title">
            <div class="title-left">
                <div class="title-info">
                    <i class="layui-icon layui-icon-return anticon mr-1" id="backBtn"></i>
                    <div class="layui-tabs layui-hide-v noborder" id="planTabs">
                        <ul class="layui-tabs-header">
                            <li lay-closable="false">作业详情</li>
                            <li lay-closable="false">覆盖率详情</li>
                        </ul>
                    </div>
                </div>
            </div>
            <div class="title-right">
                <span class="layui-font-gray">（2025-06-30—2025-06-30）</span>
            </div>
        </div>
        <hr class="m-0" />
        <div class="section">
            <!-- 作业详情 -->
            <div class="layui-tabs layui-tabs-card noborder mt-3" id="work_detail">
                <ul class="layui-tabs-header">
                    <li lay-id="temporaryPlan1">计划任务数</li>
                    <li lay-id="temporaryPlan2">实际任务数</li>
                    <li lay-id="temporaryPlan3">未完成任务数</li>


                </ul>
            </div>
            <!-- 覆盖率详情 -->
            <div class="layui-tabs layui-tabs-card noborder  mt-3" id="coverage_detail">
                <ul class="layui-tabs-header">
                    <li lay-id="periodicPlan1">全部作业覆盖数</li>
                    <li lay-id="periodicPlan2">未完全作业覆盖数</li>
                </ul>
            </div>

            <!-- 列表 -->
            <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        </div>


        <script type="text/html" id="currentTableBar">
            <a class="layui-font-blue mr-3" lay-event="detail">详情</a>
        </script>
    </div>
</div>
<script>
    layui.use(['form', 'table', 'tabs', 'miniPage', 'element'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            tabs = layui.tabs,
            laydate = layui.laydate,
            layer = layui.layer,
            util = layui.util,
            element = layui.element,
            miniPage = layui.miniPage;
        /******************** 事件 start ********************/

        // 地图页面返回事件
        $('#backBtn').on('click', function () {
            miniPage.backPageCreate()
        });
        /******************** 事件 end ********************/



        /******************** 渲染组件 start ********************/
        form.render('select'); //刷新select选择框渲染

        // 初始化选项卡
        tabs.render({
            elem: '#planTabs',
            index: 0// 默认选中
        });
        // tabs 切换后的事件
        function handleTabSwitch(tabIndex) {
            if (tabIndex === 0) {
                $('#work_detail').show();
                $('#coverage_detail').hide();
            } else if (tabIndex === 1) {
                $('#work_detail').hide();
                $('#coverage_detail').show();
            }
        }

        // planTabs 切换事件
        tabs.on('afterChange(planTabs)', function (data) {
            var tabIndex = data.index;
            handleTabSwitch(tabIndex); // 调用处理函数
        });

        // 页面加载完成后默认执行一次
        $(document).ready(function () {
            var defaultIndex = 0; // 默认选中第一个 tab
            handleTabSwitch(defaultIndex);
        });

        tabs.render({
            elem: '#work_detail',
            index: 0 // 默认选中
        });
        // tabs 切换后的事件
        tabs.on('afterChange(work_detail)', function (data) {
            console.log('afterChange===', data);
            console.log(data.index); // 切换前的选中标签索引
        });



        tabs.render({
            elem: '#coverage_detail',
            index: 0 // 默认选中
        });
        // tabs 切换后的事件
        tabs.on('afterChange(coverage_detail)', function (data) {
            console.log('afterChange===', data);
            console.log(data.index); // 切换前的选中标签索引
        });

        /******************** 渲染组件 end ********************/

        table.render({
            elem: '#currentTableId',
            url: 'api/table.json',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter'],
            cols: [[
                { field: 'time', title: '日期', minWidth: 100 },
                { field: 'name', title: '姓名', minWidth: 100 },
                { field: 'businessNames', minWidth: 100, title: '岗位' },
                { field: 'businessNames', minWidth: 100, title: '业务类型' },
                { field: 'city', minWidth: 80, title: '排班任务' },
                { field: 'time', minWidth: 150, title: '覆盖率', sort: true },
                { field: 'score', minWidth: 80, title: '所属组织' },
                { field: 'classify', minWidth: 80, title: '所属网络' },
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'grid',
size: 'lg'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            layer.alert(result, {
                title: '最终的搜索信息'
            });

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });

        /**
         * toolbar事件监听
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {   // 监听添加操作
                var content = miniPage.getHrefContent('page/table/add.html');
                var openWH = miniPage.getOpenWidthHeight();

                var index = layer.open({
                    title: '添加用户',
                    type: 1,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: [openWH[0] + 'px', openWH[1] + 'px'],
                    offset: [openWH[2] + 'px', openWH[3] + 'px'],
                    content: content,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            console.log('tool(currentTableFilter)====', obj)
            if (obj.event === 'edit') {
                var content = miniPage.getHrefContent('page/table/add.html');
                var openWH = miniPage.getOpenWidthHeight();

                var index = layer.open({
                    title: '编辑用户',
                    type: 1,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: [openWH[0] + 'px', openWH[1] + 'px'],
                    offset: [openWH[2] + 'px', openWH[3] + 'px'],
                    content: content,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('确认删除吗', function (index) {
                    obj.del();
                    layer.close(index);
                });
            } else if (obj.event === 'detail') {  // 监听详情操作
                miniPage.renderPageCreate(`page/laborOperations/laborJobManager/components/planDetail.html?id=${data.id}`)
            }
        });

        // 开启监听 折叠展开事件
        miniPage.listen()

    });
</script>